<template>
  <checkbox
    :checked="isChecked"
     :disabled="disabled"
    @tap="toggleCheck"
  >
    <slot></slot>
  </checkbox>
</template>

<script>

export default {
  name: "BooleanCheck",
  model: {
    prop: "value",
    event: "input"
  },
  props: {
    value: {
      type: [Boolean, String, Number, null],
      default: false
    },
     disabled: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    isChecked() {
      // 明确判断几种 "假" 的值
      return !(this.value === false || this.value === 0 || this.value === '' || this.value === null || this.value === undefined || this.value === 'false' || this.value === '0')
    }
  },
  methods: {
    toggleCheck() {
      if(!this.disabled){
        this.$emit("input", !this.isChecked)
      }
    }
  }
}
</script>
